package logic

import (
	"context"
	"seller_svc/models/mysql"

	"seller_svc/internal/svc"
	"seller_svc/seller"

	"github.com/zeromicro/go-zero/core/logx"
)

type SellerAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSellerAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SellerAddLogic {
	return &SellerAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品发布
func (l *SellerAddLogic) SellerAdd(in *seller.SellerAddRequest) (*seller.SellerAddResponse, error) {
	// todo: add your logic here and delete this line

	m := mysql.Seller{
		Name:   in.Name,
		Price:  float64(in.Price),
		Sales:  in.Sales,
		Coupon: int(in.Coupon),
	}

	mysql.DB.Debug().Create(&m)

	return &seller.SellerAddResponse{
		Id: int64(m.ID),
	}, nil
}
